import ResMgr from '../Managers/ResMgr';
import UIMgr from '../Managers/UIMgr';

export default class GameApp extends cc.Component {
    public static Instance: GameApp = null as unknown as GameApp;

    protected onLoad(): void {
        if (GameApp.Instance === null) {
            GameApp.Instance = this;
        } else {
            this.destroy();
            return;
        }
    }
    start() {}

    public EnterGame(): void {
        const resPkg = {
            Maps: {
                assetType: cc.Prefab,
                urls: ['Prefabs/HelloWorld'],
            },
            GUI: {
                assetType: cc.Prefab,
                urls: ['UIPrefabs/LoginUI'],
            },
        };

        ResMgr.Instance.preloadResPkg(resPkg, null, () => {
            // 加载资源
            this.EnterLogicScene();
            // end
        });
    }

    public EnterLogicScene(): void {
        // 释放3d资源
        // const mapPrefabs = ResMgr.Instance.getAsset('GUI', 'UIPrefabs/LoginUI');
        // const HelloWorld = cc.instantiate(mapPrefabs);
        // this.node.addChild(HelloWorld);
        // end
        // 释放角色
        // end
        // 释放UI视图

        console.log(UIMgr.Instance);
        UIMgr.Instance.show_ui('LoginUI');

        // const uiPrefab = ResMgr.Instance.getAsset('Maps', 'Prefabs/HelloWorld');
        // const uiView = cc.instantiate(uiPrefab);
        // cc.find('Canvas')?.addChild(uiView);
        // uiView.position.x = 300;
        // end
    }

    // update (dt) {}
}
